﻿using System;
using FollowMe.Infrastructure;
using FollowMe.Infrastructure.UnitOfWork;

namespace FollowMe.Repository
{
    public class CFUnitOfWork : IUnitOfWork, IDisposable
    {
        private IContext fmcontext;

        public CFUnitOfWork(IContext _fm)
        {
            fmcontext = _fm;
        }


        /// <summary>
        /// Commits this instance.
        // This is the only function needed from UoW when a DBContext is used.
        // The DBsets track changes etc, no need to use other classes.
        /// </summary>
        public void Commit()
        {
            fmcontext.SaveChanges();    //replace with unity at some point?
        }

        public void RegisterAmended(IAggregateRoot entity, IUnitOfWorkRepository unitofWorkRepository)
        {
            //unitofWorkRepository.PersistUpdateOf(entity); 
            //Do nothing
        }

        public void RegisterNew(IAggregateRoot entity, IUnitOfWorkRepository unitofWorkRepository)
        {
            // unitofWorkRepository.PersistCreationOf(entity); 
            //Do nothing
        }

        public void RegisterRemoved(IAggregateRoot entity, IUnitOfWorkRepository unitofWorkRepository)
        {
            //unitofWorkRepository.PersistDeletionOf(entity); 
            //Do nothing
        }

        protected virtual void Dispose(Boolean dis)
        {
            if (dis)
            {

            }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}